/**
 * Copyright (c) 2008 Luciano Bustos - riaevolution.com, All Rights Reserved.
 * 
 * Contact luchyx@riaevolution.com
 * See www.riaevolution.com
 *  
 * Permission is hereby granted, free of charge, to any person obtaining a copy of 
 * this software and associated documentation files (the "Software"), to deal in 
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all 
 * copies or substantial portions of the Software.
 * 
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE. 
 * */
package com.riaevolution.preloader
{
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.text.TextFormat;
	
	import mx.events.*;
	import mx.graphics.RoundedRectangle;
	import mx.preloaders.DownloadProgressBar;

	public class Preloader extends DownloadProgressBar {

       public var wcs:WelcomeScreen;
       public function Preloader() 
       {
            super(); 
            wcs = new WelcomeScreen();			
            this.addChild(wcs).visible = false;            
            //this.MINIMUM_DISPLAY_TIME = 1000*50;            
            DownloadProgressBar.initializingLabel = 'Iniciando giama.Prendarios';
       } 
       override protected function createChildren():void {
       		super.createChildren();
       		
       		var g:Graphics = graphics;
       		
       		g.clear();
       		g.beginFill(backgroundColor, backgroundAlpha);
			g.drawRect(0, 0, stageWidth, stageHeight);
			// Draw the outside border and fill.
			g.beginFill(0xFF6633, 0.4);	
			
			g.drawRoundRect(
				DisplayObject(this.wcs).x - 20,
				DisplayObject(this.wcs).y - 20,
				borderRect.width,
				borderRect.height,
				borderRect.cornerRadius * 2,
				borderRect.cornerRadius * 2);
				
			g.endFill();				

			g.beginFill(0x000000,1);
			g.drawRoundRect(
				DisplayObject(this.wcs).x - 18,
				DisplayObject(this.wcs).y - 18,
				borderRect.width - 4,
				borderRect.height - 4,
				borderRect.cornerRadius - 1 * 2,
				borderRect.cornerRadius - 1 * 2);
			g.endFill();
			
       }
       
     override protected function center(width:Number, height:Number):void {
       		super.center(width,height);
       		
       		DisplayObject(this.wcs).x = width / 2  - 78;
       		DisplayObject(this.wcs).y = height / 2  - 100;
       		 		
     }
       
	override protected function initProgressHandler(event:Event):void {
		super.initProgressHandler(event);
		DisplayObject(this.wcs).visible = true;       		
		DisplayObject(wcs).width = 48;
		DisplayObject(wcs).height = 48;
	}
       
      override protected function get borderRect():RoundedRectangle {
			return new RoundedRectangle(0, -60, 190, 120, 6);
	}
	override protected function get labelRect():Rectangle {
			return new Rectangle(14, 17, 140,20);
	}
	 override protected function get labelFormat():TextFormat
	{
		var tf:TextFormat = new TextFormat();
		tf.color = 0xFFFFFF;
		tf.font = "Verdana";
		tf.size = 10;
		return tf;
	}
    }
}